package com.tree.backend.exception;

import com.tree.backend.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandle {

    // 提高健壮性
    @ExceptionHandler(Exception.class)
    public Result<String> handleException(Exception e) {
        log.error("服务器异常：{}", e.getMessage());
        return Result.error(500, "服务器异常，请联系管理员");
    }

    //全局异常处理
    @ExceptionHandler(GlobalException.class)
    public Result<String> handleGlobalException(GlobalException e) {
        log.error("服务器异常：{}", e.getMessage());
        return Result.error(e.getCode(), e.getMessage());
    }
}